package com.irdstudio.efp.report.service.impl;

import com.irdstudio.basic.framework.core.base.FrameworkService;
import com.irdstudio.efp.report.service.dao.RptAccLoanDao;
import com.irdstudio.efp.report.service.domain.RptAccLoan;
import com.irdstudio.efp.report.service.facade.RptAccLoanService;
import com.irdstudio.efp.report.service.vo.RptAccLoanVO;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;
import java.util.Objects;

/**
 * Service Impl: 马上金融联合贷台账明细服务实现
 *
 * @author gcb
 * @date 2020-01-13
 */
@Service("rptAccLoanService")
public class RptAccLoanServiceImpl implements RptAccLoanService, FrameworkService {

    private static Logger logger = LoggerFactory.getLogger(RptAccLoanServiceImpl.class);

    @Autowired
    private RptAccLoanDao rptAccLoanDao;

    /**
     * 新增数据
     *
     * @param rptAccLoanVo
     * @return
     */
    @Override
    public int insert(RptAccLoanVO rptAccLoanVo) {
        logger.debug("当前新增数据为:" + rptAccLoanVo.toString());
        int num = 0;
        try {
            RptAccLoan rptAccLoan = new RptAccLoan();
            beanCopy(rptAccLoanVo, rptAccLoan);
            num = rptAccLoanDao.insert(rptAccLoan);
        } catch (Exception e) {
            logger.error("新增数据发生异常!", e);
            num = -1;
        }
        logger.debug("当前新增数据条数为:" + num);
        return num;
    }

    /**
     * 根据主键删除信息
     *
     * @param rptAccLoanVo
     * @return
     */
    @Override
    public int deleteByPk(RptAccLoanVO rptAccLoanVo) {
        logger.debug("当前删除数据条件为:" + rptAccLoanVo);
        int num = 0;
        try {
            RptAccLoan rptAccLoan = new RptAccLoan();
            beanCopy(rptAccLoanVo, rptAccLoan);
            num = rptAccLoanDao.deleteByPk(rptAccLoan);
        } catch (Exception e) {
            logger.error("删除数据发生异常!", e);
            num = -1;
        }
        logger.debug("根据条件:" + rptAccLoanVo + "删除的数据条数为" + num);
        return num;
    }

    /**
     * 根据主键更新信息
     *
     * @param rptAccLoanVo
     * @return
     */
    @Override
    public int updateByPk(RptAccLoanVO rptAccLoanVo) {
        logger.debug("当前修改数据为:" + rptAccLoanVo.toString());
        int num = 0;
        try {
            RptAccLoan rptAccLoan = new RptAccLoan();
            beanCopy(rptAccLoanVo, rptAccLoan);
            num = rptAccLoanDao.updateByPk(rptAccLoan);
        } catch (Exception e) {
            logger.error("修改数据发生异常!", e);
            num = -1;
        }
        logger.debug("根据条件:" + rptAccLoanVo + "修改的数据条数为" + num);
        return num;
    }

    /**
     * 根据主键查询详情
     *
     * @param inRptAccLoanVo
     * @return
     */
    @Override
    public RptAccLoanVO queryByPk(RptAccLoanVO inRptAccLoanVo) {
        logger.debug("当前查询参数信息为:" + inRptAccLoanVo);
        try {
            RptAccLoan queryRptAccLoan = new RptAccLoan();
            beanCopy(inRptAccLoanVo, queryRptAccLoan);
            RptAccLoan queryRslRptAccLoan = rptAccLoanDao.queryByPk(queryRptAccLoan);
            if (Objects.nonNull(queryRslRptAccLoan)) {
                return beanCopy(queryRslRptAccLoan, new RptAccLoanVO());
            } else {
                logger.debug("当前查询结果为空!");
            }
        } catch (Exception e) {
            logger.error("查询数据发生异常!", e);
        }
        return null;
    }

    @Override
    public List<RptAccLoanVO> queryReportData(RptAccLoanVO rptAccLoanVO) {
        logger.debug("当前查询参数信息为:" + rptAccLoanVO);
        List<RptAccLoanVO> list = null;
        try {
            RptAccLoan queryRptAccLoan = new RptAccLoan();
            beanCopy(rptAccLoanVO, queryRptAccLoan);
            List<RptAccLoan> queryRslRptAccLoan = rptAccLoanDao.queryReportData(queryRptAccLoan);
            list = (List<RptAccLoanVO>) beansCopy(queryRslRptAccLoan,RptAccLoanVO.class);
        } catch (Exception e) {
            logger.error("查询数据发生异常!", e);
        }
        return list;
    }

    @Override
    public int countDatas(RptAccLoanVO rptAccLoanVO) {
        logger.debug("当前查询参数信息为:" + rptAccLoanVO);
        int num = 0;
        try {
            num = rptAccLoanDao.countDatas(rptAccLoanVO);
        } catch (Exception e) {
            logger.error("查询数据发生异常!", e);
        }
        return num;
    }

    @Override
    public List<RptAccLoanVO> queryReportDataByPage(RptAccLoanVO rptAccLoanVO) {
        logger.debug("当前查询参数信息为:" + rptAccLoanVO);
        List<RptAccLoanVO> list = null;
        try {
            RptAccLoan queryRptAccLoan = new RptAccLoan();
            beanCopy(rptAccLoanVO, queryRptAccLoan);
            List<RptAccLoan> queryRslRptAccLoan = rptAccLoanDao.queryReportDataByPage(queryRptAccLoan);
            list = (List<RptAccLoanVO>) beansCopy(queryRslRptAccLoan,RptAccLoanVO.class);
        } catch (Exception e) {
            logger.error("查询数据发生异常!", e);
        }
        return list;
    }
}
